<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function Person(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
            // 向对象中添加一个方法
            this.sayName = fun;

        }
        // 将方法定义在全局变量中
        function fun() {
            alert("大家好!我是" + this.name);
        };


        var per = new Person("孙悟空", 28, "男");
        per.sayName();
        console.log(per);
    </script>


    <textarea name="" id="" cols="30" rows="10">你好</textarea>
</body>

</html>